package com.flnet.web.controller.foxwash;

import com.flnet.common.annotation.Log;
import com.flnet.common.base.AjaxResult;
import com.flnet.common.enums.BusinessType;
import com.flnet.common.page.TableDataInfo;
import com.flnet.common.utils.UUIDUtils;
import com.flnet.common.utils.poi.ExcelUtil;
import com.flnet.foxwash.domain.WServiceType;
import com.flnet.foxwash.service.IWServiceTypeService;
import com.flnet.framework.util.ShiroUtils;
import com.flnet.framework.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务类型 信息操作处理
 * 
 * @author flnet
 * @date 2019-03-20
 */
@Controller
@RequestMapping("/foxwash/wServiceType")
public class WServiceTypeController extends BaseController
{
    private String prefix = "foxwash/wServiceType";
	
	@Autowired
	private IWServiceTypeService wServiceTypeService;
	
	@RequiresPermissions("foxwash:wServiceType:view")
	@GetMapping()
	public String wServiceType()
	{
	    return prefix + "/wServiceType";
	}
	
	/**
	 * 查询服务类型列表
	 */
	@RequiresPermissions("foxwash:wServiceType:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WServiceType wServiceType)
	{
		startPage();
        List<WServiceType> list = wServiceTypeService.selectWServiceTypeList(wServiceType);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出服务类型列表
	 */
	@RequiresPermissions("foxwash:wServiceType:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WServiceType wServiceType)
    {
    	List<WServiceType> list = wServiceTypeService.selectWServiceTypeList(wServiceType);
        ExcelUtil<WServiceType> util = new ExcelUtil<WServiceType>(WServiceType.class);
        return util.exportExcel(list, "wServiceType");
    }
	
	/**
	 * 新增服务类型
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存服务类型
	 */
	@RequiresPermissions("foxwash:wServiceType:add")
	@Log(title = "服务类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WServiceType wServiceType)
	{
		wServiceType.setUuid(UUIDUtils.getUUID());
		wServiceType.setCreator(ShiroUtils.getUserId());
		return toAjax(wServiceTypeService.insertWServiceType(wServiceType));
	}

	/**
	 * 修改服务类型
	 */
	@GetMapping("/edit/{typeId}")
	public String edit(@PathVariable("typeId") Long typeId, ModelMap mmap)
	{
		WServiceType wServiceType = wServiceTypeService.selectWServiceTypeById(typeId);
		mmap.put("wServiceType", wServiceType);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存服务类型
	 */
	@RequiresPermissions("foxwash:wServiceType:edit")
	@Log(title = "服务类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WServiceType wServiceType)
	{		
		return toAjax(wServiceTypeService.updateWServiceType(wServiceType));
	}
	
	/**
	 * 删除服务类型
	 */
	@RequiresPermissions("foxwash:wServiceType:remove")
	@Log(title = "服务类型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wServiceTypeService.deleteWServiceTypeByIds(ids));
	}

	/**
	 * 服务类型状态修改
	 */
	@Log(title = "服务类型管理", businessType = BusinessType.UPDATE)
	@RequiresPermissions("foxwash:wserviceType:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(WServiceType serviceType)
	{
		return toAjax(wServiceTypeService.changeStatus(serviceType));
	}
}
